<?
function getFromYoutobe($key) //Взять ID ролика из ютуба
{
   $maska="http://www.youtube.com/results?search_type=&aq=f&search_query=";
    $key=iconv("windows-1251","utf-8", $key);
   $myURL=$maska.str_replace(" ","+",$key);
	$ch = curl_init ();
	curl_setopt ( $ch , CURLOPT_URL , $myURL);
	curl_setopt ( $ch , CURLOPT_HEADER , 0 );
	curl_setopt($ch, CURLOPT_FAILONERROR, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
	$itog=curl_exec ( $ch );
	curl_close ( $ch );
	preg_match('/qlicon="(.*?)?" alt/i',$itog,$id);
 	return "<object width='425' height='344'><param name='movie' value='http://www.youtube.com/v/{$id[1]}&hl=ru_RU&fs=1&'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/{$id[1]}&hl=ru_RU&fs=1&' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='425' height='344'></embed></object>";
}
?>
